type HttpResult<T> =
  | { state: "loading" }
  | { state: "success"; value: T }
  | { state: "error"; cause: string }
  | { state: "interrupted"; cause: string };

type Contact = {
  name: string;
  email: string;
  phone: {
    type: string;
    number: string;
  };
};

function logResponse(response: HttpResult<Contact>) {
  switch (response.state) {
    case "loading":
      console.log("Loading...");
      break;
    case "success":
      console.log(`The contact is for ${response.value.name},`);
      console.log(`Call by ${response.value.phone.number},`);
      break;
    case "error":
      console.error(`Error: ${response.cause}`);
      break;
    // deno-lint-ignore no-case-declarations
    default:
      // deno-lint-ignore no-unused-vars
      const impossible: never = response;
      break;
  }
}